home *** CD-ROM | disk | FTP | other *** search
/ IRIS Performer 2.2 Friends Demo / SGI IRIS Performer 2.2 Friends Demo.iso / friends / openworlds / tix / DialogS.tcl < prev    next >
Text File  |  1997-11-22  |  4KB  |  181 lines

  1. # The DialogShell widget lets the window manager know that it
  2. # is a dialog window. Among other things:
  3. #   -  It popups up automatically with requiring the user to hit the 
  4. #      mouse another time
  5. #   -  It centers itself over a parent widget
  6. #   -  It iconifies itself when the parent widget is iconifies
  7. #
  8. # Adapted from Joseph Wang's implementation for Tix 3.6. Rewritten to
  9. # follow the new OOP mechanism in Tix 4.0
  10. #
  11. # Original author:
  12. #
  13. # Written by Joseph Wang (joe@mit.edu)
  14. # Part of the Globewide Network Academy
  15. # Macvicar School of Education and Technology
  16. #
  17.  
  18. # If the user does not give value
  19. # the title and parent is dynamically configured.
  20. #
  21.  
  22. tixWidgetClass tixDialogShell {
  23.     -superclass tixShell
  24.     -classname  TixDialogShell
  25.     -method {
  26.     popdown popup center
  27.     }
  28.     -flag   {
  29.     -mapped -minheight -minwidth -parent -transient
  30.     }
  31.     -static {}
  32.     -configspec {
  33.     {-mapped mapped Mapped 0}
  34.     {-minwidth minWidth MinWidth 0}
  35.     {-minheight minHeight MinHeight 0}
  36.     {-transient transient Transient true}
  37.     {-parent parent Parent {}}
  38.     }
  39. }
  40.  
  41. #----------------------------------------------------------------------
  42. #        Construct widget
  43. #----------------------------------------------------------------------
  44.  
  45. proc tixDialogShell::ConstructWidget {w} {
  46.     upvar #0 $w data
  47.  
  48.     tixChainMethod $w ConstructWidget
  49.  
  50.     # Set the title of this shell appropriately
  51.     #
  52.     if {$data(-title) == {}} {
  53.     # dynamically sets the title
  54.     #
  55.     set data(-title) [winfo name $w]
  56.     }
  57.     wm title $w $data(-title)
  58.  
  59.     # Set the parent of this dialog shell
  60.     #
  61.     if {$data(-parent) == {}} {
  62.     set data(-parent) [winfo parent $w]
  63.     }
  64.  
  65.     # Set the minsize and maxsize of the thing
  66.     #
  67.     wm minsize $w $data(-minwidth) $data(-minheight)
  68. }
  69.  
  70. # The next procedures manage the dialog boxes
  71. #
  72. proc tixDialogShell::popup {w {parent {}}} {
  73.     upvar #0 $w data
  74.  
  75.     # First update to make sure the boxes are the right size
  76.     #
  77.     update idletask
  78.  
  79.     # Then we set the position and update
  80.     #
  81.     tixDialogShell::center $w $parent
  82.  
  83. #    if [winfo ismapped $w] {
  84. #    wm withdraw $w
  85. #    }
  86.  
  87.     # and now make it visible. Viola!  Centered over parent.
  88.     #
  89.     wm deiconify $w
  90. }
  91.  
  92. # This procedure centers a dialog box over a window making sure that the 
  93. # dialog box doesn't appear off the screen
  94. #
  95. # However, if the parent is smaller than this dialog, make this dialog
  96. # appear at parent(x,y) + (20,20)
  97. #
  98. proc tixDialogShell::center {w {parent {}}} {
  99.     upvar #0 $w data
  100.     # Tell the WM that we'll do this ourselves.
  101.     wm sizefrom $w user
  102.     wm positionfrom $w user
  103.  
  104.     if {$parent == {}} {
  105.     set parent $data(-parent)
  106.     }
  107.     if [catch {set parent [winfo toplevel $parent]}] {
  108.     set parent "."
  109.     }
  110.  
  111.     # Where is my parent and what are it's dimensions
  112.     #
  113.     if {$parent != ""} {
  114.     set pargeo [split [wm geometry $parent] "+x"]
  115.     set parentW [lindex $pargeo 0]
  116.     set parentH [lindex $pargeo 1]
  117.     set parx [lindex $pargeo 2]
  118.     set pary [lindex $pargeo 3]
  119.  
  120.     if {[tixGetBoolean -nocomplain $data(-transient)]} {
  121.         wm transient $w $parent
  122.     }
  123.     } else {
  124.     set parentW [winfo screenwidth $w]
  125.     set parentH [winfo screenheight $w]
  126.     set parx 0
  127.     set pary 0
  128.     set parent [winfo parent $w]
  129.     }
  130.  
  131.     # What are is the offset of the virtual window
  132.     set vrootx [winfo vrootx $parent]
  133.     set vrooty [winfo vrooty $parent]
  134.  
  135.     # What are my dimensions ?
  136.     set dialogW [winfo reqwidth $w]
  137.     set dialogH [winfo reqheight $w]
  138.  
  139.     if {$dialogW < [expr $parentW-30] || $dialogW < [expr $parentH-30]} {
  140.     set dialogx [expr $parx+($parentW-$dialogW)/2+$vrootx]
  141.     set dialogy [expr $pary+($parentH-$dialogH)/2+$vrooty]
  142.     } else {
  143.     # This dialog is too big. Place it at (parentx, parenty) + (20,20)
  144.     #
  145.     set dialogx [expr $parx+20+$vrootx]
  146.     set dialogy [expr $pary+20+$vrooty]
  147.     }
  148.  
  149.     set maxx [expr "[winfo screenwidth  $parent] - $dialogW"]
  150.     set maxy [expr "[winfo screenheight $parent] - $dialogH"]
  151.  
  152.     # Make sure it doesn't go off screen
  153.     #
  154.     if {$dialogx < 0} {
  155.     set dialogx 0
  156.     } else {
  157.     if {$dialogx > $maxx} {
  158.         set dialogx $maxx
  159.     }
  160.     }
  161.     if {$dialogy < 0} {
  162.     set dialogy 0
  163.     } else {
  164.     if {$dialogy > $maxy} {
  165.         set dialogy $maxy
  166.     }
  167.     }
  168.  
  169.     # set my new position (and dimensions)
  170.     #
  171.     if {[wm geometry $w] == "1x1+0+0"} {
  172.     wm geometry $w $dialogW\x$dialogH\+$dialogx\+$dialogy
  173.     }
  174. }
  175.  
  176. proc tixDialogShell::popdown {w args} {
  177.     wm withdraw $w
  178. }
  179.  
  180.